package cn.aezo.minions.gen;

import cn.aezo.minions.gen.handler.GenCodeHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author smalle
 * @date 2019-07-31 17:47
 */
@Component
public class Plugins {
    @Value("${minions.handlers}")
    String[] handlers;

    public List<GenCodeHandler> getGenCodeHandler() {
        List<GenCodeHandler> list = new ArrayList<>();
        for (String handler : handlers) {
            try {
                Class<?> c = this.getClass().getClassLoader().loadClass(handler);
                GenCodeHandler genCodeHandler = (GenCodeHandler) c.newInstance();
                list.add(genCodeHandler);
            } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                e.printStackTrace();
            }
        }
        return list;
    }
}
